package com.ts.api.http.receive.biz;

import com.gitee.apanlh.util.base.MapUtils;
import com.gitee.apanlh.util.dataformat.JsonUtils;
import com.gitee.apanlh.web.model.vo.RequestVO;
import com.ts.api.module.api.convert.core.annotation.ApiReceive;
import com.ts.api.module.api.convert.core.annotation.ApiReceiveConvertType;
import com.ts.api.module.api.convert.receive.entity.ApiReceiveApply;
import com.ts.api.module.api.convert.receive.entity.ApiReceiveDecrypt;
import com.ts.api.module.api.convert.receive.entity.ApiReceiveNotice;
import com.ts.api.module.api.convert.receive.entity.ApiReceivePhoneMd5DataExchange;
import com.ts.api.module.api.convert.receive.handler.ApiReceivePhoneMd5ConvertHandler;
import com.ts.api.module.api.entity.ApiUserRequest;

import java.util.Map;

/**
 *  测试渠道全流程
 *
 *  @author Pan
 */
@ApiReceive(apiClientId = "1809126674252320768",type = ApiReceiveConvertType.API_CHANNEL_PHONE_MD5)
public class ApiReceivePhoneMd5AATestV3 implements ApiReceivePhoneMd5ConvertHandler {

    @Override
    public Map<String, String> requireParam(RequestVO requestVO) throws Exception {
        return null;
    }

    @Override
    public ApiReceiveDecrypt decrypt(Map<String, String> paramMap, RequestVO requestVO) throws Exception {
        String body = requestVO.getBody();
        return new ApiReceiveDecrypt(body);
    }

    @Override
    public ApiUserRequest parseDataExchange(ApiReceiveDecrypt apiReceiveDecrypt) throws Exception {
        String data = apiReceiveDecrypt.getData();
        ApiUserRequest apiUserRequest = JsonUtils.toBean(data, ApiUserRequest.class);
        return apiUserRequest;
    }

    @Override
    public Map<String, Object> respDataExchange(ApiReceivePhoneMd5DataExchange dataExchangeMessage) throws Exception {
        return MapUtils.newLinkedHashMap(newMap -> {
            if (dataExchangeMessage.hasBizSuc()) {
                newMap.put("code", "0");
                newMap.put("msg", "撞库成功");
            } else {
                newMap.put("code", dataExchangeMessage.getBizCode());
                newMap.put("msg", dataExchangeMessage.getBizMsg());
            }
        });
    }

    @Override
    public ApiUserRequest parseApply(ApiReceiveDecrypt apiReceiveDecrypt) throws Exception {
        String data = apiReceiveDecrypt.getData();
        ApiUserRequest apiUserRequest = JsonUtils.toBean(data, ApiUserRequest.class);
        return apiUserRequest;
    }

    @Override
    public Map<String, Object> respApply(ApiReceiveApply applyMessage) throws Exception {
        return MapUtils.newLinkedHashMap(newMap -> {
            if (applyMessage.hasBizSuc()) {
                newMap.put("code", "0");
                newMap.put("msg", "进件成功");
            } else {
                newMap.put("code", applyMessage.getBizCode());
                newMap.put("msg", applyMessage.getBizMsg());
            }
        });
    }

    @Override
    public void fieldMapping(ApiUserRequest apiUserRequest) {

    }

    @Override
    public Object reqPullApplyNotice(ApiReceiveNotice apiReceiveNotice) {
        return null;
    }

    @Override
    public boolean respPullApplyNotice(String responseBody) {
        return false;
    }

    @Override
    public Object reqPushApplyNotice(ApiReceiveNotice apiReceiveNotice) {
        return null;
    }

    @Override
    public boolean respPushApplyNotice(String responseBody) {
        return false;
    }

}
